From d188fcc9d148c4b8f71590f63d538647d46beb25 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Oct 2014 16:33:52 -0700 Subject: [PATCH] Fix a repeated `cargo test` with examples The examples output directory was accidentally taken into account twice, and this removes one source of the output directory confusion. --- src/cargo/ops/cargo_rustc/context.rs | 5 ++--- tests/test_cargo_test.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index e3e22b343..47751b8ee 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -225,9 +225,8 @@ impl<'a, 'b> Context<'a, 'b> { let stem = target.file_stem(); let mut ret = Vec::new(); - if target.is_example() { - ret.push(format!("examples/{}{}", stem, self.target_exe)); - } else if target.is_bin() || target.get_profile().is_test() { + if target.is_example() || target.is_bin() || + target.get_profile().is_test() { ret.push(format!("{}{}", stem, self.target_exe)); } else { if target.is_dylib() { diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 901499c44..89d7f9e27 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -1254,3 +1254,24 @@ test!(example_bin_same_name { assert_that(p.process(p.bin("examples/foo")), execs().with_status(0).with_stdout("example\n")); }) + +test!(test_with_example_twice { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/bin/foo.rs", r#"fn main() { println!("bin"); }"#) + .file("examples/foo.rs", r#"fn main() { println!("example"); }"#); + + println!("first"); + assert_that(p.cargo_process("test").arg("-v"), + execs().with_status(0)); + assert_that(&p.bin("examples/foo"), existing_file()); + println!("second"); + assert_that(p.process(cargo_dir().join("cargo")).arg("test").arg("-v"), + execs().with_status(0)); + assert_that(&p.bin("examples/foo"), existing_file()); +}) -- 2.30.2